# Readme for the Replication Package "Financing Multinationals" by Fan and Luo

This document describes the replication package for the paper "Financing Multinationals". The replication package contains two parts, empirics and quantitative, each correspoending to one part of the paper.  This document explains the input, the program, and the output for each of the two parts.


## System Requirements:

- Windows 10
- MATLAB R2023b
- Julia 1.10
- Python 3.11 (with the package `pandas`)
- Stata 17.0 (with the packages `estout`, `reghdfe`, `ppml`, 
`ppmlhdfe`, `binscatter2`)

## Empirics

**Folder and File Structure:**

- *DATA*: the data used in creating the tables. The following list the files and the source data

  - *TABLE_A7_DATA.dta*, *TABLE1_DATA.dta*: firm balance sheet and ownership data (Orbis), Penn World Table (gdp and TFP), OECD (FDI restrictiveness policy), World Bank (Credit GDP ratio, business tax, financial development index), bilateral distance (CEPII), and bilateral FDI (Ramondo et. al). 

    These files are removed from the uploaded version of the replication package because the Orbis data are subject to data agreement. Readers interested in replicating the results could obtain access through the data vendor BvD.

    
  - *FIGURE_1A_DATA.dta*, *FIGURE_1B_DATA.dta*, *TABLE_A1_DATA.dta*, *TABLE_A2_DATA.dta*, *TABLE_A3_DATA.dta* : raw data from the Penn World Table (gdp and TFP), OECD (FDI restrictiveness policy), World Bank (Credit GDP ratio, business tax, financial development index), bilateral distance (CEPII), and bilateral FDI (Ramondo et. al) 

  - *TABLE_A4_DATA1.dta*, *TABLE_A4_DATA2.dta*, *TABLE_A5_DATA.dta*, *FIGURE_A1_DATA*: US BEA (data on position, sales, WL, assets and all derivative variables), WB(Credit GDP ratio, business tax, financial development index), bilateral distance (CEPII database). 

- *CODE*: do files that read the data and make figures and tables

  - *S1.do*: uses input *TABLE_A1_DATA, FIGURE_1A_DATA, FIGURE_1B_DATA TABLE_A2_DATA*
  - *S2.do*: uses input *TABLE_A4_DATA1, TABLE_A4_DATA2, TABLE_A5_DATA, FIGURE_A1_DATA*
  - *S3.do*: uses input *TABLE1_DATA, TABLE_A7_DATA* (these inputs are removed from the uploaded version of the replication package)

- *OUTPUT*: an empty path. Figures and tables made by the do files will appear here.

**Replication Steps:**

1. Change directory to *CODE*
2. Execute S1.do to replicate  Figure 1a and Figure 1b, Table A1, Table A2, Table A3.
3. Execute S2.do to replicate Figure A.1, Table A4, Table A5
4. Execute S3.do to replicate Table 1, Table A6, Table A7; the uploaded version of the replicaiton package does not run becasue the firm-level data are proprietary. Readers can acquire access to the firm-level data through BvD.


## Quantitative

The quantitative part of the replication package contains two folders—`quantitative_switching_costs` and `quantitative_no_FDI`—for solving the benchmark model and the model without the FDI-MP nexus, respectively.

### `quantitative_switching_costs`: Solving the Benchmark Model

**Folder and File Structure:**

- `input`: input files for the model
- `tables`: table output from the model
- `figures`: figure output from the model
- `output`: all other output files
- `source`: source code
- `works`: intermediate files
- Script files `d0`–`d8`: Julia code for solving the model
- Script files `e0`–`e1`: Python code for processing model output
- Script files `s0`–`s4`: MATLAB code for processing model output
- Script files `v0`–`v2`: Stata code for producing model validation results

**Replication Steps:**
1. Change directory to `quantitative_switching_costs`
2. In the Julia command line, type `]`; type `activate .`; and type `instantiate` to install the packages specified in `Project.toml`
3. Run Julia script files `d0`–`d8` in sequence
4. In the Python command line, run `e0`–`e1` in sequence
5. In MATLAB, run `s0`–`s4` in sequence
6. In Stata, run `v0`–`v2` in sequence

**Output Figures and Tables Referenced in the Draft and Appendix:**

- Table 3: `tables/static_dynamic_welfare_gains_comparison.csv`
- Figure 2a: `figures/aggregate_stock_data.png`
- Figure 2b, 2c: `figures/lambda_overtime_plot.png`, `figures/mu_overtime_plot.png`
- Figure 3a, 3b: `figures/cf_FDI_01_switching_costs.png`, `figures/cf_FDI_08_switching_costs.png`
- Figure 3c: `figures/delta_log_w_HUN_formatted.png`
- Table C.1: `tables/CountrySpecificTables.xlsx`
- Table C.2: `tables/tab_lambda_mu_validation.txt`
- Table C.3: `tables/wedge_validation.txt`
- Figure C.3: `figures/bilateral_mp_model_vs_data.png`, `figures/inward_mp_model_vs_data.png`
- Figure C.4: `figures/dynamic_gains_varying_primatives.png`

### `quantitative_no_FDI`: Solving the Model without the FDI-MP Nexus

**Replication Steps:**
1. In MATLAB, run script files `s1`–`s5`

**Output:**
- `tables/cf_history_dependence_no_FDI_panels.csv`
- `tables/cf_openness_from_closed_history_dependence_no_FDI.csv`

This output is used as input to the main quantitative model to generate Figure 6 and Table 6.